package com.example.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.TUser;
import com.example.service.UserService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author example
 * @since 2018-12-11
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	// http://localhost:8080/example/user/save?userName=张三&age=18&email=472132032@qq.com
	@RequestMapping("save")
	public String save(TUser user) {
		userService.save(user);
		return "ok";
	}
	
	// http://localhost:8080/example/user/list
	@RequestMapping("list")
	public List<TUser> list() {
		List<TUser> list = userService.list();
		return list;
	}
	
	//http://localhost:8080/example/user/device/category
	@RequestMapping("device/category")
	public Page<Map<String, Object>> deviceCategory(){
		Page<Map<String, Object>> page = new Page<>(1, 10);
		List<Map<String, Object>> records = userService.getMultiTablePageCondition(page,1L);
		page.setRecords(records);
		return page;
	}
}
